﻿/**  版本信息模板在安装目录下，可自行修改。
* Code_Rule.cs
*
* 功 能： N/A
* 类 名： Code_Rule
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2022/5/17 8:40:06   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using System.Data.SQLite;
//using Maticsoft.DBUtility;//Please add references
namespace ElectricalTest.DAL
{
    /// <summary>
    /// 数据访问类:Code_Rule
    /// </summary>
    public partial class Code_Rule
    {
        public Code_Rule()
        { }
        #region  BasicMethod

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string rule_name)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from Code_Rule");
            strSql.Append(" where rule_name=@rule_name ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@rule_name", DbType.String,2147483647)			};
            parameters[0].Value = rule_name;

            return DbHelperSQLite.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(ElectricalTest.Model.Code_Rule model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Code_Rule(");
            strSql.Append("rule_name,rule_detail,rule_describe)");
            strSql.Append(" values (");
            strSql.Append("@rule_name,@rule_detail,@rule_describe)");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@rule_name", DbType.String,2147483647),
					new SQLiteParameter("@rule_detail", DbType.String,2147483647),
					new SQLiteParameter("@rule_describe", DbType.String,2147483647)};
            parameters[0].Value = model.rule_name;
            parameters[1].Value = model.rule_detail;
            parameters[2].Value = model.rule_describe;

            int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ElectricalTest.Model.Code_Rule model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Code_Rule set ");
            strSql.Append("rule_detail=@rule_detail,");
            strSql.Append("rule_describe=@rule_describe");
            strSql.Append(" where rule_name=@rule_name ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@rule_detail", DbType.String,2147483647),
					new SQLiteParameter("@rule_describe", DbType.String,2147483647),
					new SQLiteParameter("@rule_name", DbType.String,2147483647)};
            parameters[0].Value = model.rule_detail;
            parameters[1].Value = model.rule_describe;
            parameters[2].Value = model.rule_name;

            int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string rule_name)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Code_Rule ");
            strSql.Append(" where rule_name=@rule_name ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@rule_name", DbType.String,2147483647)			};
            parameters[0].Value = rule_name;

            int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string rule_namelist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Code_Rule ");
            strSql.Append(" where rule_name in (" + rule_namelist + ")  ");
            int rows = DbHelperSQLite.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ElectricalTest.Model.Code_Rule GetModel(string rule_name)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select rule_name,rule_detail,rule_describe from Code_Rule ");
            strSql.Append(" where rule_name=@rule_name ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@rule_name", DbType.String,2147483647)			};
            parameters[0].Value = rule_name;

            ElectricalTest.Model.Code_Rule model = new ElectricalTest.Model.Code_Rule();
            DataSet ds = DbHelperSQLite.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ElectricalTest.Model.Code_Rule DataRowToModel(DataRow row)
        {
            ElectricalTest.Model.Code_Rule model = new ElectricalTest.Model.Code_Rule();
            if (row != null)
            {
                if (row["rule_name"] != null)
                {
                    model.rule_name = row["rule_name"].ToString();
                }
                if (row["rule_detail"] != null)
                {
                    model.rule_detail = row["rule_detail"].ToString();
                }
                if (row["rule_describe"] != null)
                {
                    model.rule_describe = row["rule_describe"].ToString();
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select rule_name,rule_detail,rule_describe ");
            strSql.Append(" FROM Code_Rule ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQLite.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM Code_Rule ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQLite.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.rule_name desc");
            }
            strSql.Append(")AS Row, T.*  from Code_Rule T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQLite.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SQLiteParameter[] parameters = {
                    new SQLiteParameter("@tblName", DbType.VarChar, 255),
                    new SQLiteParameter("@fldName", DbType.VarChar, 255),
                    new SQLiteParameter("@PageSize", DbType.Int32),
                    new SQLiteParameter("@PageIndex", DbType.Int32),
                    new SQLiteParameter("@IsReCount", DbType.bit),
                    new SQLiteParameter("@OrderType", DbType.bit),
                    new SQLiteParameter("@strWhere", DbType.VarChar,1000),
                    };
            parameters[0].Value = "Code_Rule";
            parameters[1].Value = "rule_name";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQLite.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

